package com.example.blank700.alert_dialog;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.AlertDialog;//对话框
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.widget.Toast;

public class Alert_Dialog extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alert_dialog);
        Builder dialog=new AlertDialog.Builder(Alert_Dialog.this);
        dialog.setIcon(android.R.drawable.ic_dialog_info);
        dialog.setTitle("Welcome");
        dialog.setMessage("Welcome to use this program");
        dialog.setPositiveButton("Yes", new OnClickListener() {//第一个用setPositiveButton
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Toast.makeText(this,"you choose yes_button",Toast.LENGTH_SHORT).show();//Alert里不能用Toast，因为这两个都是提示框
            }
        });
        dialog.setNegativeButton("No", new OnClickListener() {//第二个用setNegativeButton，第一个和第二个不能用相同的setxxxxxxx，如果这样的话就会只有一个按钮
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Toast.makeText(this,"you choose no_button",Toast.LENGTH_SHORT).show();
            }
        });
        dialog.create();
        dialog.show();
    }
}
